package com.andoridtools.weidgt;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.andoridtools.R;
import com.andoridtools.utils.ScreenUtils;

/**
 * 右上角菜单
 */

public class PopWinTopRight extends PopupWindow {
    WindowManager.LayoutParams params = null;

    /**
     * this view outside's id must be pop_layout
     *
     * @param popView
     */
    public PopWinTopRight(final Context context, final View popView, View displayView) {
        this.setOutsideTouchable(true);
        this.setContentView(popView);
        this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
        this.setWidth(RelativeLayout.LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);

        this.showAtLocation(displayView, Gravity.TOP | Gravity.RIGHT,  60, 190);
        params = ((Activity) context).getWindow().getAttributes();
        params.alpha = 0.7f;
        ((Activity) context).getWindow().setAttributes(params);


        this.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                params = ((Activity) context).getWindow().getAttributes();
                params.alpha = 1f;
                ((Activity) context).getWindow().setAttributes(params);
            }
        });
    }
}